package com.itheima.test;

public class test8 {
    public static void main(String[] args) {
        //需求：复制数组
        int[] arr = {1,5,7,3,8,10};
        int[] newArr = copyArray(arr,1,3);
        for (int i = 0; i < newArr.length; i++) {
            System.out.println(newArr[i]);
        }

    }
    public static int[] copyArray(int[] arr,int from,int to){
        //定义新数组
        int[] newArr = new int[to-from];

        //把原来数组中对应的元素直接拷贝到新数组中
        //伪造索引的思想
        int index= 0;
        for (int i = from; i < to; i++) {
            newArr[index] = arr[i];
            index++;
        }
        return newArr;
    }
}
